<template>
  <div class="h-full w-full flex flex-col">
    <titleBar>猫眼电影</titleBar>
    <div type="text" class="content flex-1 overflow-auto mt-5">
      <input
        class="border border-none w-[90%] mx-[5%] h-[40px]"
        placeholder="手机号"
        v-model="tel"
      />
      <input
        type="password"
        class="border-none w-[90%] mx-[5%] h-[40px]"
        placeholder="密码"
        v-model="pwd"
      />
      <div class="w-[90%] pl-[5%]">
        <button
          class="
            h-[40px]
            w-[100%]
            bg-[#e54847]
            rounded-[30px]
            border-0
            text-white
            tracking-[10px]
            mt-[20px]
          "
          @click="login()"
        >
          登陆
        </button>
        <button
          class="
            h-[40px]
            w-[100%]
            bg-[#e54847]
            rounded-[30px]
            border-0
            text-white
            tracking-[10px]
            mt-[20px]
          "
        @click="register"
        >
          注册
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { Collapse, CollapseItem, Popup } from "vant";
import { ref, reactive } from "vue";
import titleBar from "../components/title-bar.vue";
import API from "../utils/API/index.js";
import { useRouter, useRoute } from "vue-router";
//获取路由管理对象
const router = useRouter();
const route = useRoute();
const activeName = ref("0");
const show = ref(false);
const tel = ref(null);
const pwd = ref(null);
const showPopup = () => {
  show.value = true;
};
const login = () => {
  console.log(tel.value, pwd.value);
  API.userinfo.getAllUserInfo().then((res) => {
    let userlist = [...res];
    let a = 0;
    userlist.forEach((item) => {
      // console.log(item);
      //判断数据库中是否存在此用户
      if (item.custom_tel == tel.value && item.custom_pwd == pwd.value) {
        console.log("登陆成功!");
        console.log(item.id);
        router.push({
          name: "userinfo",
          query: {
            id: item.id,
          },
        });
      } else {
        a++;
      }
    });
    if (a >= userlist.length) {
      console.log("用户名或密码错误!");
    }
  });
};
const register=()=>{
   router.push({
          name: "register",
        });
}
</script>

<style scoped>
</style>